import React from 'react';
import {Badge, Icon, Tooltip, message} from 'antd';
import Constants from "../utils/Constants";
import Utils from "../utils";

module.exports = [
  {
    key: 'id',
    title: 'ID',
    dataType: 'int',
    primary: true,
    showType: 'normal',
    showInTable: true,
    showInForm: true,
    disabled: true,
    render: (text, record) => text
  },
  {
    key: 'name',
    title: '应用名称',
    dataType: 'varchar',
    validator: [{required: true, message: '此项必填'}]

  },
  {
    key: 'thumb',
    title: '缩略图',
    dataType: 'varchar',
    sizeLimit: 200,
    url: 'goods/uploadImage',
    showType: 'image',
    width: 100,
    render(text) {
      return text ? <img src={text} className={'row-thumb'}/> : '';
    }
  },
  {
    key: 'desc',
    title: '简介',
    dataType: 'varchar',
    validator: [{required: true, message: '此项必填'}]

  },
  {
    key: 'key',
    title: 'key',
    dataType: 'varchar',
    showInForm: false,
    render: (text, record) => record.$$rawData.key
  },
  {
    key: 'secret',
    title: 'secret',
    dataType: 'varchar',
    showInForm: false,
    render: (text, record) => {
      const showSecret = () => {
        message.info(text);
      };

      return (
        <div style={{cursor: 'pointer'}} onClick={showSecret}>
          <Tooltip placement="top" title='查看secret'>
            <Icon type="zoom-in"/>
          </Tooltip>
        </div>
      );
    }
  },
  {
    key: 'status',
    title: '状态',
    dataType: 'int',
    showType: 'select',
    options: Utils.map2kvArr(Constants.APP_STATUS_MAP),
    render: (record) => <Badge status={record === '启用' ? "success" : "error"} text={record}/>
  },
  {
    key: 'createTime',
    title: '创建时间',
    dataType: 'datetime',
    showInForm: false
  }
];